package com.gljx.web.service.impl;

import com.gljx.web.Entity.SubjectTwoRegentry;
import com.gljx.web.Entity.User;
import com.gljx.web.dao.SubjectTwoRegentryMapper;
import com.gljx.web.service.CustomLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class SubjectTwoRegentryServiceImpl implements com.gljx.web.service.SubjectTwoRegentryService {

	@Autowired
	private SubjectTwoRegentryMapper subjectTwoRegentryMapper;

	@Autowired
	private CustomLogService customLogService;

	@Override
	public List<SubjectTwoRegentry> selSubjectTwoRegentryByParentId(String fid,String studentName) {
		// TODO Auto-generated method stub
		return subjectTwoRegentryMapper.selSubjectTwoRegentryByParentId(fid, studentName);
	}

	@Override
	public SubjectTwoRegentry selSharCarTwoRegBySutid(String lcsjid, String studentid) {
		// TODO Auto-generated method stub
		return subjectTwoRegentryMapper.selSharCarTwoRegBySutid(lcsjid, studentid);
	}

	@Override
	public SubjectTwoRegentry selChangeCarTwoRegBySutid(String lcsjid, String studentid) {
		// TODO Auto-generated method stub
		List<SubjectTwoRegentry> subjectTwoRegentryList=subjectTwoRegentryMapper.selChangeCarTwoRegBySutid(lcsjid, studentid);
		if(subjectTwoRegentryList.size() > 0){
			//System.out.println(" 学生id: "+subjectTwoRegentryList.get(0).getCfstudentid());
			return subjectTwoRegentryList.get(0);
		}
		return null;
	}

	@Override
	public int deleteByParentId(String parentid,User user,String fbizdate,String fnumber) {
		// TODO Auto-generated method stub
		if(user != null){//根据父类id查找子类信息
			List<SubjectTwoRegentry> subjectTwoRegentries =subjectTwoRegentryMapper.selSubjectTwoRegentryByParentId(parentid,null);
			for (int i = 0; i < subjectTwoRegentries.size(); i++) {
				//添加学员的服务日志
				customLogService.addLog("考试管理",  "删除了学员:"+subjectTwoRegentries.get(i).getCfstudentno()+subjectTwoRegentries.get(i).getStudentName()+
						",科目二考试登记!车型:"+subjectTwoRegentries.get(i).getCfsqzjcxdh()+",教练:"+subjectTwoRegentries.get(i).getJlzname()+",考试日期:"+fbizdate+",单据编号:"+fnumber, subjectTwoRegentries.get(i).getCfstudentid(), user.getFid());
			}
		}
		return subjectTwoRegentryMapper.deleteByParentId(parentid);
	}

	@Override
	public int addSubjectTwoRegentry(SubjectTwoRegentry subjectTwoRegentry) {
		// TODO Auto-generated method stub
		return subjectTwoRegentryMapper.insertSelective(subjectTwoRegentry);
	}

	@Override
	public SubjectTwoRegentry selSubjectTwoRegentryByStuid(String parentid, String studentid) {
		// TODO Auto-generated method stub
		return subjectTwoRegentryMapper.selSubjectTwoRegentryByStuid(parentid, studentid);
	}

}
